package com.zmytest.controller;

import com.zmytest.annotation.CreateSession;
import com.zmytest.annotation.Permission;
import com.zmytest.dto.LoginDto;
import com.zmytest.dto.LoginResponseDto;
import com.zmytest.dto.ResponseDto;
import com.zmytest.exception.AccessException;
import com.zmytest.repository.AccountRepository;
import com.zmytest.repository.LoginRecordRepository;
import com.zmytest.service.LoginService;
import com.zmytest.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created on 2018/12/19.
 *
 * @author zhangmingyu
 */
@RestController
public class TestController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    @CreateSession(flag = "$OUT.success",key = "LOGIN_INFO",value = "$OUT.data")
    public ResponseDto<LoginResponseDto> login(@RequestBody LoginDto loginDto){
        return loginService.login(loginDto);
    }

    @GetMapping("/user-can-access")
    @Permission({"admin","user"})
    @ResponseBody
    public ResponseDto test(){
        System.out.println("hello test");
        return ResponseDto.success("success");
    }

    @GetMapping("/admin-can-access")
    @Permission
    @ResponseBody
    public ResponseDto test2(){
        System.out.println("hello test2");
        return null;
    }

    @GetMapping("/super-user-can-access")
    @Permission({"admin","manager"})
    @ResponseBody
    public ResponseDto test3(){
        System.out.println("hello test3");
        return null;
    }

}
